define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'coperion/index' + location.search,
                    add_url: 'coperion/add',
                   // edit_url: 'coperion/edit',
                    del_url: 'coperion/del',
                    multi_url: 'coperion/multi',
                    table: 'coperion',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'dccode', title: __('Dccode'),operate: 'LIKE %...%',},
                        {field: 'desc', title: __('Desc'),operate: 'LIKE %...%', formatter: function(value){return (value.toString().substr(0, 30).concat("..."))}},
                        {field: 'Specifications', title: __('Specifications')},
                        {field: 'devmanufacturer', title: __('Devmanufacturer')},
                        {field: 'manufacturer', title: __('Manufacturer')},
                        {field: 'devmanufacturercode', title: __('Devmanufacturercode')},
                        {field: 'manufacturercode', title: __('Manufacturercode')},
                        {field: 'minstock', title: __('Minstock')},
                        {field: 'maxstock', title: __('Maxstock')},
                        {field: 'nowstock', title: __('Nowstock')},
                        {field: 'systock', title: __('Systock')},
                        {field: 'status', title: __('Status'), operate:false,formatter: Table.api.formatter.status},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: __('Operate'), table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'detail',
                                text: __('Detail'),
                                icon: 'fa fa-list',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: 'coperion/detail'
                            }],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
